using Game.Networking.Utils;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace Game.UI
{
    public class LinkFolderWindow : UIWindow
    {
        public Button ConfirmButton;

        public TMP_Text Title;
        public TMP_Text Description;
        public TMP_InputField InputField;

        IComputingUnitUserDataProvider _dataProvider;

        protected override void Awake()
        {
            base.Awake();

            var isServer = NetworkOptions.StartServer;
            if (isServer)
            {
                Debug.Log("Have no use in server mode");
                return;
            }

            _dataProvider = new ClientComputingUnitUserDataProvider();

            ConfirmButton.onClick.RemoveAllListeners();
            ConfirmButton.onClick.AddListener(OnComfirmButtonClick);
        }

        void OnComfirmButtonClick()
        {
            if (!string.IsNullOrEmpty(InputField.text))
            {
                _dataProvider.CreateNewCodeFile(InputField.text, string.Empty);
            }

            HideWindow();
        }
    }
}